﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="Timer.js" type="text/javascript"></script>

    <script>


        var timer = new Timer("show();", 1000, Number.POSITIVE_INFINITY, false);

        function $(id) {
            return document.getElementById(id)
        }

        function start() {
            timer.Start();
            $("btn_Start").disabled = true;
            $("btn_Stop").disabled = false;
        }
        function show() {

            $("tbx1").value = new Date().toLocaleTimeString();
        }
        function show2() {

            $("tbx1").value = parseInt($("tbx1").value) + 1;
        }

        function stop() {
            timer.Stop();
            $("btn_Start").disabled = false;
            $("btn_Stop").disabled = true;
        }

        function pause() {
            timer.Pause(checkPause, 500);
            $("btn_Pause").disabled = true;
            $("btn_Resume").disabled = false;
        }

        function resume() {
            timer.Resume();
            $("btn_Pause").disabled = false;
            $("btn_Resume").disabled = true;
        }

        function checkPause() {

            var t = $("tbx2").value == "1";

            if (t) {
                $("btn_Pause").disabled = false;
                $("btn_Resume").disabled = true;
            }
            return t;
        }

        function changeProperty() {

            timer.Stop();
            timer.ExeCount = 0;
            timer.MaxExeCount = 5;
            timer.FirstExe = false;
            timer.Interval = 2000;
            timer.Expression = "show2()";
            $("tbx1").value = 0;
            timer.Start();

            $("btn_Start").disabled = true;
            $("btn_Stop").disabled = false;
            $("btn_Resume").disabled = true;
            $("btn_Pause").disabled = false;
            $("btn_ChangeProperty").disabled = true;
        }

        function dispose() {

            timer.Dispose();
            $("btn_Start").disabled = true;
            $("btn_Stop").disabled = true;
            $("btn_Resume").disabled = true;
            $("btn_Pause").disabled = true;
            $("btn_Dispose").disabled = true;
            $("btn_ChangeProperty").disabled = true;

        }
    </script>

</head>
<body>
    <input type="text" id="tbx1" />
    <input type="text" id="tbx2" />
    <button onclick="start()" id="btn_Start">
        开始</button>
    <button onclick="stop()" id="btn_Stop">
        停止</button>
    <button onclick="pause()" id="btn_Pause">
        暂停</button>
    <button onclick="resume()" id="btn_Resume">
        继续</button>
    <button onclick="changeProperty()" id="btn_ChangeProperty">
        改变属性</button>
    <button onclick="dispose()" id="btn_Dispose">
        释放资源</button>
</body>
</html>
